﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.IO;

namespace DrawTools
{
    //测试图元
    public class ToolImage : ToolRectangle
	{
        public ToolImage()
		{
            Cursor = new Cursor(Common.FunctionClass.getRunPath() + @"\Resources\Test.cur");
		}

        public override void OnMouseDown(KKDraw drawArea, MouseEventArgs e)
        {
            Point point = drawArea.BackTrackMouse(new Point(e.X, e.Y));
            DrawImage drawImage = new DrawImage(point.X, point.Y, 1, 1);
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                if (!Directory.Exists(Common.FunctionClass.getRunPath() + @"/Images/"))
                {
                    Directory.CreateDirectory(Common.FunctionClass.getRunPath() + @"/Images/");
                }
                string saveImagePath = Common.FunctionClass.getRunPath() + @"/Images/" 
                    +Guid.NewGuid().ToString()+ openFileDialog.SafeFileName;
                File.Copy(openFileDialog.FileName, saveImagePath);

                drawImage.ImagePath = saveImagePath;
                AddNewObject(drawArea, drawImage);
            }
        }

	}
}
